package com.org.web.api.mobile;

import com.org.platform.model.ResultModel;
import java.io.InputStream;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping(value = {"/mobile/category"})
public class MobileCategoryController {


    @RequestMapping(value = {"/getCategory"})
    public ResultModel getCategory() {
        try {
            Resource resource = new ClassPathResource("doc/category.json");
            InputStream inputStream = resource.getInputStream();
//            File jsonFile = ResourceUtils.getFile("classpath:doc/category.json");
//            String json = FileUtils.readFileToString(jsonFile, Charset.forName("utf-8"));
            String str = IOUtils.toString(inputStream, "utf-8");
            return ResultModel.newSuccess(str);
        } catch (Exception ex) {
            log.error("ex", ex);
            return ResultModel.newFail("获取文件失败");
        }
    }

}
